package cily.utils
{
	import flash.display.GradientType;
	import flash.display.LineScaleMode;
	import flash.display.Shape;
	import flash.display.SpreadMethod;
	import flash.display.Sprite;
	import flash.geom.Matrix;
	/**
	 * ...
	 * @author 
	 */
	public class ShapeUtil
	{
		
		public static function getCircle(p_radius : Number ,   p_color : uint = 0xFF0000 , p_alpha : Number = .5):Shape
		{
			var s: Shape = new Shape()
			s.graphics.beginFill(p_color , p_alpha);
			s.graphics.drawCircle(0, 0,p_radius );
			s.graphics.endFill();
			
			return s;		
		}
		
		public static function getGradientCircle(p_radius : Number = 100 , 
												p_alpha1 : Number = 1 ,p_alpha2 : Number = 0 ,
												p_color1: uint = 0xFF0000 , p_color2 : uint = 0x000000):Shape
		{
			
			var fillType:String = GradientType.RADIAL;
			var colors:Array = [p_color1, p_color2];
			var alphas:Array = [p_alpha1, p_alpha2];
			var ratios:Array = [0x00, 0xFF];
			var matr:Matrix = new Matrix();
				matr.createGradientBox( p_radius , p_radius ,0 , -p_radius/2 , - p_radius/2);
			 var spreadMethod:String = SpreadMethod.PAD;
			 var s: Shape = new Shape()
			  s.graphics.beginGradientFill(fillType, colors, alphas, ratios, matr, spreadMethod);  
			  //s.graphics.beginGradientFill(fillType, colors, alphas, ratios);  
			  s.graphics.drawCircle(0,0,p_radius / 2);
			
			return s;		
		}
		
		public static function getGradientShape(p_w : Number = 100 , p_h: Number = 100  , 
												p_alpha1 : Number = .5 ,p_alpha2 : Number = .0 ,
												p_color1: uint = 0x000000 , p_color2 : uint = 0x000000,
												p_ratioW : Number = 1.5 , p_rotation : Number = 0):Shape
		{
			
			var fillType:String = GradientType.LINEAR;
			var colors:Array = [p_color1, p_color2];
			var alphas:Array = [p_alpha1, p_alpha2];
			var ratios:Array = [0x00, 0xFF];
			var matr:Matrix = new Matrix();
				matr.createGradientBox(p_w*p_ratioW, p_h, p_rotation, 0, 0);
			 var spreadMethod:String = SpreadMethod.PAD;
			 var s: Shape = new Shape()
			  s.graphics.beginGradientFill(fillType, colors, alphas, ratios, matr, spreadMethod);  
			  s.graphics.drawRect(0,0,p_w,p_h);
			
			return s;		
		}
		
		public static function getShape(p_w : Number = 100 , p_h: Number = 100, p_color : uint = 0xFF0000 , p_alpha : Number = .5):Shape
		{
			var s: Shape = new Shape()
			s.graphics.beginFill(p_color , p_alpha);
			s.graphics.drawRect(0, 0, p_w , p_h);
			s.graphics.endFill();
			
			return s;		
		}
		
		public static function getSprite(p_w : Number = 100 , p_h: Number = 100, p_color : uint = 0xFF0000 , p_alpha : Number = .5):Sprite
		{
			var s: Sprite = new Sprite()
			s.graphics.beginFill(p_color , p_alpha);
			s.graphics.drawRect(0, 0, p_w , p_h);
			s.graphics.endFill();
			
			return s;		
		}
		
		public static function getLineH(p_w : Number = 10 , p_color : uint = 0xFF0000):Shape
		{
			var l: Shape = new Shape()
			l.graphics.lineStyle(1 , p_color ,  1 , false , LineScaleMode.NONE , null , null , 0);
			l.graphics.beginFill(p_color , 0);
			l.graphics.drawRect(0, 0, p_w , 0);
			l.graphics.endFill();			
			return l;			
		}
		
		public static function getLineV(p_h : Number = 10 , p_color : uint = 0xFF0000):Shape
		{
			var l: Shape = new Shape()
			l.graphics.lineStyle(1 , p_color ,  1 ,false , LineScaleMode.NONE , null , null , 0);
			l.graphics.beginFill(p_color , 0);
			l.graphics.drawRect(0, 0, 0 , p_h);
			l.graphics.endFill();			
			return l;			
		}
		
	}

}